package in.iqing.model.sp;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import in.iqing.App;

/**
 * Created by ZuoShu on 15/7/6.
 */
public class AccountSP {
    private static SharedPreferences accountSP;

    private static SharedPreferences getSharedPreference() {
        if (accountSP == null) {
            accountSP = App.getInstance().getSharedPreferences("account", Context.MODE_PRIVATE);
        }
        return accountSP;
    }

    public static void clear() {
        getSharedPreference().edit().clear().apply();
    }

    public static String getMobile() {
        return getSharedPreference().getString("mobile", "");
    }

    public static void setMobile(String mobile) {
        getSharedPreference().edit().putString("mobile", mobile).apply();
    }

    public static String getUserName() {
        return getSharedPreference().getString("username", "");
    }

    public static void setUserName(String name) {
        getSharedPreference().edit().putString("username", name).apply();
    }

    public static int getUserId() {
        return getSharedPreference().getInt("userid", -1);
    }

    public static void setUserId(int id) {
        getSharedPreference().edit().putInt("userid", id).apply();
    }

    public static boolean isLogin() {
        return !TextUtils.isEmpty(getSharedPreference().getString("mobile", ""));
    }

    public static void clearLoginAccount() {
        setMobile("");
        setUserName("");
        setUserId(-1);
    }

}
